<template>
	<view @click.stop="handleLike">
		<text class="cuIcon-appreciatefill" v-if="is_like" style="color:#E24E47"/>
		<text class="cuIcon-appreciate" v-else/>
		<text>{{likes_count}}</text>
	</view>
</template>

<script>
	export default {
		props: {
			item:{
				type:Object,
				default:()=>({})
			}
		},
		data() {
			return {
				is_like: 0,
				likes_count: 0
			}
		},
		methods: {
			async handleLike() {
				//评论点赞
				let api = !!this.is_like ? this.$h.api.commentModel.postCommentUnLike : this.$h.api.commentModel.postCommentLike
				let query = {
					comment_id: this.item.id
				}
				let {
					code
				} = await this.waitingLoading(api, true)(query)
				if (code == 1) {
					this.is_like ? this.likes_count-- : this.likes_count++
					console.log(this.likes_count)
					this.is_like = this.is_like ? 0 : 1
				}
			},
		},
		created() {
			this.is_like = this.item.is_like
			this.likes_count = this.item.likes_count
		}
	}
</script>

<style>
</style>
